package com.css.fxfzaqbz.modules.data.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzaqbz.base.upload.service.AttachmentInfoService;
import com.css.fxfzaqbz.constants.FxfzConstants;
import com.css.fxfzaqbz.constants.YNEnum;
import com.css.fxfzaqbz.modules.assess.service.BigCasualtiesService;
import com.css.fxfzaqbz.modules.assess.service.BigDisasterService;
import com.css.fxfzaqbz.modules.assess.service.BigSecondService;
import com.css.fxfzaqbz.modules.assess.service.EarthEntityService;
import com.css.fxfzaqbz.modules.assess2.service.KrTaskService;
import com.css.fxfzaqbz.modules.assess2.service.UTaskService;
import com.css.fxfzaqbz.modules.data.entity.ImportantActivity;
import com.css.fxfzaqbz.modules.data.entity.Region;
import com.css.fxfzaqbz.modules.data.entity.Report;
import com.css.fxfzaqbz.modules.data.entity.WorkerInfo;
import com.css.fxfzaqbz.modules.data.queryParams.ImportantActivityQueryParams;
import com.css.fxfzaqbz.modules.data.repository.ImportantActivityRepository;
import com.css.fxfzaqbz.modules.data.repository.ReportRepository;
import com.css.fxfzaqbz.modules.data.service.BigDisposeManagerService;
import com.css.fxfzaqbz.modules.data.service.ImportantActivityService;
import com.css.fxfzaqbz.modules.supergraph.exception.CustomException;
import com.css.fxfzaqbz.util.*;
import com.css.fxfzaqbz.web.PlatformSessionContext;
import com.css.fxfzaqbz.zcpt.sys.entity.SUser;
import com.css.fxfzaqbz.zcpt.sys.service.SUserService;
import com.css.fxfzaqbz.zcpt.sys.service.SysAreaService;
import com.css.fxfzaqbz.zcpt.sys.service.SysRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Transactional(rollbackFor = Exception.class)
public class ImportantActivityServiceImpl implements ImportantActivityService {
    @Resource
    ImportantActivityRepository importantActivityRepository;
    @Resource
    AttachmentInfoService attachmentInfoService;
    @Resource
    KrTaskService krTaskService;
    @Resource
    UTaskService uTaskService;
    @Resource
    BigCasualtiesService bigCasualtiesService;
    @Resource
    BigDisasterService bigDisasterService;
    @Resource
    BigSecondService bigSecondService;
    @Resource
    EarthEntityService earthEntityService;
    @Resource
    SUserService sUserService;
    @Resource
    SysRoleService sysRoleService;
    @Resource
    SysAreaService sysAreaService;
    @Resource
    BigDisposeManagerService bigDisposeManagerService;

    @Resource
    ReportRepository reportRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ImportantActivity updateImportantActivity(ImportantActivity importantActivity) {

        importantActivity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());

        importantActivity.setUpdateUser(PlatformSessionUtils.getUserId());
//        ImportantActivity importantActivity1 = importantActivityRepository.updateImportantActivity(importantActivity);
//        if (!importantActivity.getIaOpinion().equals(importantActivity1.getIaOpinion())) {
//            return importantActivityRepository.updateOpinionStatus(importantActivity1);
//        }
        ImportantActivity importantActivity1 = importantActivityRepository.getImportantActivityById(importantActivity.getIaId());
        if (importantActivity.getIaOpinionStatus() == null) {
            importantActivity.setIaOpinionStatus(importantActivity1.getIaOpinionStatus());
        }
        if (importantActivity.getIaOpinion() == null) {
            importantActivity.setIaOpinion(importantActivity1.getIaOpinion());
        } else if (!importantActivity.getIaOpinion().equals(importantActivity1.getIaOpinion())) {
            importantActivity.setIaOpinionStatus(YNEnum.Y.toString());
        }
        //根据活动id,查看上传的报告
        List<Report> reports = reportRepository.getReport1ByIaId(importantActivity.getIaId());
        if (reports.size()!=0){
            Report report = reports.get(0);
            report.setCbId(importantActivity.getCbshId());
            report.setBmId(importantActivity.getBmshId());
            report.setLdId(importantActivity.getLdshId());
            reportRepository.updateReport(report);
        }
        handleTask(importantActivity1,importantActivity);
        return importantActivityRepository.updateImportantActivity(importantActivity);
    }

    private void handleTask(ImportantActivity oldObject, ImportantActivity newObject) {
        List<String> dutie1 = getTask1(oldObject);
        if (dutie1.size()==3) return;
        List<String> dutie2 = getTask1(newObject);
        if (!dutie1.contains("房屋地震灾害分析评估")&&dutie2.contains("房屋地震灾害分析评估")){
            //添加三张表
            krTaskService.saveTask(newObject);//重点场所风险评估
            uTaskService.saveTask(newObject);//需紧急安置人员
            bigCasualtiesService.saveTask(newObject);//人口伤亡评估
            bigDisasterService.saveTask(newObject);//房屋地震灾害风险评估
        }
        if (!dutie1.contains("地震环境及监测能力分析")&&dutie2.contains("地震环境及监测能力分析")){
            //添加一条数据
            earthEntityService.saveTask(newObject);//地震危险性评估
        }
        if (!dutie1.contains("地震灾害风险排查及建议")&&dutie2.contains("地震灾害风险排查及建议")){
            //添加三条数据
            bigSecondService.saveTask(newObject);//次生灾害隐患评估
            //添加处置要点分析 辅助对策
            bigDisposeManagerService.saveTask(newObject);
        }
    }

    private List<String> getTask1(ImportantActivity object) {
        List<String> strings = new ArrayList<>();
        String iaZddwYwrys = object.getIaZddwYwrys();
        int index = iaZddwYwrys.indexOf("&", iaZddwYwrys.indexOf("&") + 1);
        String[] split = iaZddwYwrys.substring(index+1).split("&");
        strings.addAll(Arrays.asList(split));
        String iaSsdwYwrys = object.getIaSsdwYwrys();
        int index1 = iaSsdwYwrys.indexOf("&", iaSsdwYwrys.indexOf("&") + 1);
        String[] split1 = iaSsdwYwrys.substring(index1+1).split("&");
        strings.addAll(Arrays.asList(split1));
        String iaXtdwYwrys = object.getIaXtdwYwrys();
        int index2 = iaXtdwYwrys.indexOf("&", iaXtdwYwrys.indexOf("&") + 1);
        String[] split2 = iaXtdwYwrys.substring(index2+1).split("&");
        strings.addAll(Arrays.asList(split2));
        strings=strings.stream().distinct().collect(Collectors.toList());
        return strings;
    }


    @Override
    @Transactional
    public ImportantActivity saveImportantActivity(ImportantActivity importantActivity) {
        importantActivity.setIaId(UUIDGenerator.getUUID());
        importantActivity.setDelFlag(YNEnum.N.toString());
        importantActivity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        String userID = PlatformSessionContext.getUserID();
        importantActivity.setCreateUser(userID);
        importantActivity.setIaActivityStatus(YNEnum.N.toString());
        importantActivity.setCreateTime2(PlatformDateUtils.getCurrentTimestamp());
        importantActivity.setIaOpinion("初步评估建党100周年庆祝活动期间北京地区发生5.0级以上地震的可能性不大。");
        importantActivity.setIaOpinionStatus(YNEnum.N.toString());
        ImportantActivity importantActivity1 = importantActivityRepository.saveImportantActivity(importantActivity);
        //添加6个表
        saveAssData(importantActivity1);
        return importantActivity1;
    }

    private void saveAssData(ImportantActivity importantActivity1) {
        List<WorkerInfo> zddwYwrys = importantActivity1.getZddwYwrys();
        if (zddwYwrys != null && zddwYwrys.size() > 0) {
            for (WorkerInfo zddwYwry : zddwYwrys) {
                List<String> duties = zddwYwry.getDuties();
                if (duties != null && duties.size() > 0) {
                   /* if (duties.contains("地震灾害风险等级量化评估")) {
                        //添加六张表
                        krTaskService.saveTask(importantActivity1);//重点场所风险评估
                        uTaskService.saveTask(importantActivity1);//需紧急安置人员
                        bigCasualtiesService.saveTask(importantActivity1);//人口伤亡评估
                        bigDisasterService.saveTask(importantActivity1);//房屋地震灾害风险评估
                        bigSecondService.saveTask(importantActivity1);//次生灾害隐患评估
                        earthEntityService.saveTask(importantActivity1);//地震危险性评估
                    }
                    if (duties.contains("辅助对策分析")) {
                        //添加两条数据
                        bigDisposeManagerService.saveTask(importantActivity1);
                    }*/
                    if (duties.contains("房屋地震灾害分析评估")) {
                        //添加三张表
                        krTaskService.saveTask(importantActivity1);//重点场所风险评估
                        uTaskService.saveTask(importantActivity1);//需紧急安置人员
                        bigCasualtiesService.saveTask(importantActivity1);//人口伤亡评估
                        bigDisasterService.saveTask(importantActivity1);//房屋地震灾害风险评估
                    }
                    if (duties.contains("地震环境及监测能力分析")) {
                        //添加一条数据
                        earthEntityService.saveTask(importantActivity1);//地震危险性评估
                    }
                    if (duties.contains("地震灾害风险排查及建议")) {
                        //添加三条数据
                        bigSecondService.saveTask(importantActivity1);//次生灾害隐患评估
                        //添加处置要点分析 辅助对策
                        bigDisposeManagerService.saveTask(importantActivity1);
                    }

                }

            }
        }
        List<WorkerInfo> ssdwYwrys = importantActivity1.getSsdwYwrys();
        if (ssdwYwrys != null && ssdwYwrys.size() > 0) {
            for (WorkerInfo ssdwYwry : ssdwYwrys) {
                List<String> duties = ssdwYwry.getDuties();
                if (duties != null && duties.size() > 0) {
              /*      if (duties.contains("地震灾害风险等级量化评估")) {
                        //添加六张表
                        krTaskService.saveTask(importantActivity1);//重点场所风险评估
                        uTaskService.saveTask(importantActivity1);//需紧急安置人员
                        bigCasualtiesService.saveTask(importantActivity1);//人口伤亡评估
                        bigDisasterService.saveTask(importantActivity1);//房屋地震灾害风险评估
                        bigSecondService.saveTask(importantActivity1);//次生灾害隐患评估
                        earthEntityService.saveTask(importantActivity1);//地震危险性评估
                    }
                    if (duties.contains("辅助对策分析")) {
                        //添加两条数据
                        bigDisposeManagerService.saveTask(importantActivity1);
                    }*/

                    if (duties.contains("房屋地震灾害分析评估")) {
                        //添加三张表
                        krTaskService.saveTask(importantActivity1);//重点场所风险评估
                        uTaskService.saveTask(importantActivity1);//需紧急安置人员
                        bigCasualtiesService.saveTask(importantActivity1);//人口伤亡评估
                        bigDisasterService.saveTask(importantActivity1);//房屋地震灾害风险评估
                    }
                    if (duties.contains("地震环境及监测能力分析")) {
                        //添加一条数据
                        earthEntityService.saveTask(importantActivity1);//地震危险性评估
                    }
                    if (duties.contains("地震灾害风险排查及建议")) {
                        //添加三条数据
                        bigSecondService.saveTask(importantActivity1);//次生灾害隐患评估
                        //添加处置要点分析 辅助对策
                        bigDisposeManagerService.saveTask(importantActivity1);
                    }
                }

            }
        }
        List<WorkerInfo> xtdwYwrys = importantActivity1.getXtdwYwrys();
        if (xtdwYwrys != null && xtdwYwrys.size() > 0) {
            for (WorkerInfo xtdwYwry : xtdwYwrys) {
                List<String> duties = xtdwYwry.getDuties();
                if (duties != null && duties.size() > 0) {
                   /* if (duties.contains("地震灾害风险等级量化评估")) {
                        //添加六张表
                        krTaskService.saveTask(importantActivity1);//重点场所风险评估
                        uTaskService.saveTask(importantActivity1);//需紧急安置人员
                        bigCasualtiesService.saveTask(importantActivity1);//人口伤亡评估
                        bigDisasterService.saveTask(importantActivity1);//房屋地震灾害风险评估
                        bigSecondService.saveTask(importantActivity1);//次生灾害隐患评估
                        earthEntityService.saveTask(importantActivity1);//地震危险性评估
                    }
                    if (duties.contains("辅助对策分析")) {
                        //添加两条数据
                        bigDisposeManagerService.saveTask(importantActivity1);
                    }*/
                    if (duties.contains("房屋地震灾害分析评估")) {
                        //添加三张表
                        krTaskService.saveTask(importantActivity1);//重点场所风险评估
                        uTaskService.saveTask(importantActivity1);//需紧急安置人员
                        bigCasualtiesService.saveTask(importantActivity1);//人口伤亡评估
                        bigDisasterService.saveTask(importantActivity1);//房屋地震灾害风险评估
                    }
                    if (duties.contains("地震环境及监测能力分析")) {
                        //添加一条数据
                        earthEntityService.saveTask(importantActivity1);//地震危险性评估
                    }
                    if (duties.contains("地震灾害风险排查及建议")) {
                        //添加三条数据
                        bigSecondService.saveTask(importantActivity1);//次生灾害隐患评估
                        //添加处置要点分析 辅助对策
                        bigDisposeManagerService.saveTask(importantActivity1);
                    }
                }

            }
        }
    }

    @Override
    public Map<String, Object> getAllImportantActivity(ImportantActivityQueryParams queryParams) throws UnsupportedEncodingException {
        if (!PlatformObjectUtils.isEmpty(queryParams.getProvinceId())) {
            String province = sysAreaService.getAreaNameByAreaId(queryParams.getProvinceId());
            queryParams.setIaProvince(province);
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getCityId())) {
            String city = sysAreaService.getAreaNameByAreaId(queryParams.getCityId());
            queryParams.setIaCity(city);
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getCountiesId())) {
            String counties = sysAreaService.getAreaNameByAreaId(queryParams.getCountiesId());
            queryParams.setIaCounties(counties);
        }
        String userId = PlatformSessionContext.getUserID();
        String user = sUserService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        String role = sysRoleService.getRoleByUserId(userId);
        List<Map> maps = JSONObject.parseArray(role, Map.class);//一个人可能有多个角色
        //当前登录人所有的角色
        StringBuilder roles = new StringBuilder();
        for (int i = 0; i < maps.size(); i++) {
            Map map = maps.get(i);
            roles.append(map.get("roleCode") + ",");
        }
        String allRole = roles.toString();
        //如果所有角色包括省级管理员
        if (allRole.contains(FxfzConstants.AQBZ_SJGLY_ROLE)) {
            if (PlatformObjectUtils.isEmpty(sUser.getProvinceId())) {
                return null;
            }
            queryParams.setProvinceId(sUser.getProvinceId());
        }
        //如果所有角色包括国家级管理员
        if (allRole.contains(FxfzConstants.AQBZ_GJJGLY_ROLE)) {
            queryParams.setProvinceId("");
        }
//        //如果所有角色包括活动管理员
//        if (allRole.contains(FxfzConstants.AQBZ_HDGLY_ROLE)) {
//            queryParams.setDlrId(userId);
//        }
//        //如果所有角色包括业务人员
//        if (allRole.contains(FxfzConstants.AQBZ_YERY_ROLE)) {
//            return null;
//        }
        Map<String, Object> map = importantActivityRepository.getAll(queryParams);
        if (!allRole.contains(FxfzConstants.AQBZ_SJGLY_ROLE) && !allRole.contains(FxfzConstants.AQBZ_GJJGLY_ROLE)) {
            return map;
        }
        Map<String, Object> map1 = importantActivityRepository.getAllImportantActivityParams(queryParams);

        Integer total = (Integer) map.get("total");
        Integer total1 = (Integer) map1.get("total");

        List<ImportantActivity> importantActivities = new ArrayList<>();
        int count = 0;
        if (total != 0) {
            count = count + total;
            List<ImportantActivity> Activities = (List<ImportantActivity>) map.get("rows");
            for (ImportantActivity activity : Activities) {
                importantActivities.add(activity);
            }
        }
        if (total1 != 0) {
            count = count + total1;
            List<ImportantActivity> Activities = (List<ImportantActivity>) map1.get("rows");
            for (ImportantActivity activity : Activities) {
                importantActivities.add(activity);
            }
        }
        Map<String, Object> hashMap = new HashMap<>();
        hashMap.put("totle", count);
        hashMap.put("rows", importantActivities);
        return hashMap;
    }

    @Override
    public ImportantActivity getImportantActivityById(String id) {
        ImportantActivity importantActivity = importantActivityRepository.getImportantActivityById(id);
        return importantActivity;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteImportantActivitys(List<String> ids, String userId) {
        List<String> list = new ArrayList<>();
        for (String id : ids) {
            List<Report> allReportById = reportRepository.getAllReportById(id);
            List<String> idList = allReportById.stream().map(e -> e.getSrId()).collect(Collectors.toList());
            list.addAll(idList);
        }
        if (list.size() != 0) {
            reportRepository.delReports(list, PlatformDateUtils.getCurrentTimestamp(), PlatformSessionUtils.getUserId());
        }

        Timestamp timestamp = PlatformDateUtils.getCurrentTimestamp();
        importantActivityRepository.deleteImportantActivitysById(ids, timestamp, userId);
    }

    @Override
    public List<ImportantActivity> searchList(ImportantActivityQueryParams queryParams) {
        List<ImportantActivity> list = importantActivityRepository.searchList(queryParams);
        for (ImportantActivity importantActivity : list) {
            System.out.println(importantActivity.toString());
        }
        return list;

    }

    @Override
    public String getNewIAId() {
        Date startTime = getStartTime();
        Timestamp startTimestamp = new Timestamp(startTime.getTime());
        Date endTime = getEndTime();
        Timestamp endTimestamp = new Timestamp(endTime.getTime());
        String count = importantActivityRepository.getNewIAId(startTimestamp, endTimestamp);
        String code = CodeUtil.getCode();//20220930001
        String s = code.substring(0, 11 - count.length());
        String ss = s + (Integer.parseInt(count) + 1);
        return ss;

//            String newIaId;
//            String dateStr = maxIAId.substring(0, 8);
//            String serialNo = maxIAId.substring(8);
//            // 开始比对日期
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//            String date = sdf.format(new Date());
//
//        // 获取流水号
//            if (date.equals(dateStr)) {
//                newIaId = CodeUtil.getCode();
//            } else {
//                newIaId = CodeUtil.getCode();
//            }
//            return newIaId;
    }

    @Override
    public List<ImportantActivity> getAllActivity() {
        String userId = PlatformSessionContext.getUserID();
        String user = sUserService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        String role = sysRoleService.getRoleByUserId(userId);
        List<Map> maps = JSONObject.parseArray(role, Map.class);//一个人可能有多个角色
        //当前登录人所有的角色
        StringBuilder roles = new StringBuilder();
        for (int i = 0; i < maps.size(); i++) {
            Map map = maps.get(i);
            roles.append(map.get("roleCode") + ",");
        }
        String allRole = roles.toString();
        String provinceId = sUser.getProvinceId();
        if (provinceId == null) {
            return null;
        }
        //如果所有角色包括国家级管理员
        if (allRole.contains(FxfzConstants.AQBZ_GJJGLY_ROLE)) {
            provinceId = null;
        }
        return importantActivityRepository.getAllActivity(provinceId);
    }

    @Override
    public void updateActivityEndStatus(String iaId) {
        Timestamp timestamp = PlatformDateUtils.getCurrentTimestamp();
        krTaskService.upStatus(iaId);//重点场所风险评估
        uTaskService.upStatus(iaId);//需紧急安置人员
        bigCasualtiesService.upStatus(iaId);//人口伤亡评估
        bigDisasterService.upStatus(iaId);//房屋地震灾害风险评估
        bigSecondService.upStatus(iaId);//次生灾害隐患评估
        earthEntityService.upStatus(iaId);
        bigDisposeManagerService.upStatus(iaId);
        importantActivityRepository.updateActivityEndStatus(timestamp, iaId);
    }

    @Override
    public List<String> getAllSiteName(String province, String city, String counties) {
        return importantActivityRepository.getAllSiteName(province, city, counties);
    }

    @Override
    public List<String> getAllSiteName1(Region region) {
        return importantActivityRepository.getAllSiteName1(region);
    }

    @Override
    public String getCodeByIaId(String iaId) {
        return importantActivityRepository.getCodeByIaId(iaId);
    }


    private Date getStartTime() {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTime();
    }

    private Date getEndTime() {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime();
    }

    @Override
    public Map<String, Object> getAll(ImportantActivityQueryParams queryParams) {
        //根据当前用户的角色权限获取sql
        String sql = this.getSqlByRole();
        return importantActivityRepository.getAllByRole(queryParams, sql);
    }

    @Override
    public String getRole() {
        String userId = PlatformSessionContext.getUserID();
        String user = sUserService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        String role = sysRoleService.getRoleByUserId(userId);
        List<Map> maps = JSONObject.parseArray(role, Map.class);//一个人可能有多个角色
        //当前登录人所有的角色
        StringBuilder roles = new StringBuilder();
        for (int i = 0; i < maps.size(); i++) {
            Map map = maps.get(i);
            roles.append(map.get("roleCode") + ",");
        }
        String allRole = roles.toString();
        if (sUser.getProvinceId() == null || sUser.getProvinceId().isEmpty()) {
            throw new CustomException("请完善当前登陆人所属省市信息");
        }
        if(allRole.contains(FxfzConstants.AQBZ_GJJGLY_ROLE)){
            return "0";
        }
        String provinceId = sUser.getProvinceId();
        return provinceId;
    }

    @Override
    public String getExamine(String iaId) {
        //根据活动id,查看上传的报告
        List<Report> reports = reportRepository.getReport1ByIaId(iaId);
        if (reports.size()!=0){
            if (!"0".equals(reports.get(0).getSrStatus())){
                return "1";
            }
        }
        return "0";
    }

    private String getSqlByRole() {
        String userId = PlatformSessionContext.getUserID();
        String user = sUserService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        String role = sysRoleService.getRoleByUserId(userId);
        List<Map> maps = JSONObject.parseArray(role, Map.class);//一个人可能有多个角色
        //当前登录人所有的角色
        StringBuilder roles = new StringBuilder();
        for (int i = 0; i < maps.size(); i++) {
            Map map = maps.get(i);
            roles.append(map.get("roleCode") + ",");
        }
        String allRole = roles.toString();
        if (sUser.getProvinceId() == null || sUser.getProvinceId().isEmpty()) {
            throw new CustomException("请完善当前登陆人所属省市信息");
        }
        String provinceId = sUser.getProvinceId();
        String province = sysAreaService.getAreaNameByAreaId(provinceId);
        String roleSql = null;
        //只要角色包括国家级管理员 ,就能看到所有数据
        if (!allRole.contains(FxfzConstants.AQBZ_GJJGLY_ROLE)) {
            //既是省级管理员也是活动管理员
            if (allRole.contains(FxfzConstants.AQBZ_SJGLY_ROLE)&&allRole.contains(FxfzConstants.AQBZ_HDGLY_ROLE))
                //能看到自己省的数据跟自己创建的活动
                roleSql =" and (ia_province ='"+province+"' or create_user ='"+userId+"')";
            //只是省级管理员
            else if (allRole.contains(FxfzConstants.AQBZ_SJGLY_ROLE) && !allRole.contains(FxfzConstants.AQBZ_HDGLY_ROLE))
                //只能看到自己省的数据
                roleSql =" and ia_province ='"+province+"'";
            //不是国家级,不是省级,是活动管理员
            else if (!allRole.contains(FxfzConstants.AQBZ_SJGLY_ROLE)&&allRole.contains(FxfzConstants.AQBZ_HDGLY_ROLE))
                //只能看到自己创建的活动
                roleSql =" and create_user ='"+userId+"'";
        }
        return roleSql;
    }
}
